﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TugasAkhir.Models;
using TugasAkhir.Objects;

namespace TugasAkhir
{
    public partial class Dosen : System.Web.UI.Page
    {
        private DosenObject dosen;

        protected void Page_Load(object sender, EventArgs e)
        {
            CheckSession();
            CheckRole();
        }

        private void CheckRole()
        {
            if (int.Parse(Session["id_role"].ToString().Substring(2)) == 2)
            {
                this.boxPertanyaan.Attributes.Remove("hidden");
                this.boxPengaturanPertanyaan.Attributes.Remove("hidden");
                this.boxAnalisis.Attributes.Remove("hidden");
                this.boxRekomendasi.Attributes.Remove("hidden");
                //this.boxPengaturanRekomendasi.Attributes.Remove("hidden");
                //this.headerRekomendasi.InnerHtml = "Rekomendasi";
            }
            else if (int.Parse(Session["id_role"].ToString().Substring(2)) == 3)
            {
                this.boxAnalisis.Attributes.Remove("hidden");
                this.boxRekomendasi.Attributes.Remove("hidden");
                //this.boxDaftarRekomendasi.Attributes.Remove("hidden");
                //this.headerRekomendasi.InnerHtml = "Rekomendasi";
            }
            else
            {
                this.boxAnalisis.Attributes.Remove("hidden");
                this.boxPengaturanRekomendasi.Attributes.Remove("hidden");
                this.boxRekomendasi.Attributes.Remove("hidden");
                this.boxDaftarRekomendasi.Attributes.Remove("hidden");
                //this.boxDaftarRekomendasi.Attributes.Remove("hidden");
            }
        }

        private void CheckSession()
        {
            if (Session["id_role"] != null && Session["id_role"].ToString() != "RL01" && Session["id_role"].ToString().StartsWith("RL"))
            {
                DosenModel.GetDosenDetail(Session["username"].ToString(), out this.dosen);
                this.litName.Text = dosen.NamaDosen;
            }
            else
            {
                Response.Redirect("/Login.aspx");
            }
        }

        protected void lnkLogout_Click(object sender, EventArgs e)
        {
            Session["id_role"] = "";
            Session["username"] = "";
            CheckSession();
        }
    }
}